package com.itzdl.service.impl;

import java.util.List;

import com.itzdl.dao.NewsDao;
import com.itzdl.dao.UserDao;
import com.itzdl.dao.impl.UserDaoImpl;
import com.itzdl.domain.News;
import com.itzdl.domain.User;
import com.itzdl.service.UserService;

public class UserServiceImpl implements UserService {
    
	private UserDao userDao;
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	private NewsDao newsDao;
	public void setNewsDao(NewsDao newsDao) {
		this.newsDao = newsDao;
	}

	@Override
	public Integer find_name(String name,String password) {
		// TODO Auto-generated method stub
		return userDao.find_name(name,password);
	}

	@Override
	public Integer login_action(String name, String password) {
		// TODO Auto-generated method stub
		return userDao.login_action(name, password);
	}

	@Override
	public Integer shoucang(String name, Integer newsId) {
		// TODO Auto-generated method stub
	    List<News> news=newsDao.findById(newsId);
			for(News newss:news) {
				User user=userDao.shoucang(name);
				user.getNews().add(newss);
				newss.getUser().add(user);
				userDao.save(user);
				return 1;
			}
		return 0;
	}

	@Override
	public Integer upload(String user_name, String image_path) {
		// TODO Auto-generated method stub
		return userDao.upload(user_name,image_path);
	}

	@Override
	public List<User> touxiang(String user_name) {
		// TODO Auto-generated method stub
		return userDao.touxiang(user_name);
	}
}
